package com.sdz.chapitre15;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

/**
 * @author tony
 *
 */
public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		FileInputStream fis;
		BufferedInputStream bis;
		FileChannel fc;
		
		try {
			
			fis = new FileInputStream(new File("villes_france2.csv"));
			bis = new BufferedInputStream(fis);
			
			long time = System.currentTimeMillis();
			
			while (bis.read() != -1);
			
			System.out.println("Temps d'exec : " + (System.currentTimeMillis() - time));
			
			fis = new FileInputStream(new File("villes_france2.csv"));
			fc = fis.getChannel();
			int size = (int)fc.size();
			ByteBuffer bBuff = ByteBuffer.allocate(size);
			
			time = System.currentTimeMillis();
			
			// demarrage lecture
			fc.read(bBuff);
			
			// on prepare a la lecture avec l'appel a flip
			bBuff.flip();
			
			System.out.println("Temps d'exec : " + (System.currentTimeMillis() - time));
			
			// retourne un tableau d'octets
			byte[] tabByte = bBuff.array();
			
			
			
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			
		}
		
		
	}

}
